﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using TopUtility;
using TopModel;
using System.Web.Security;
public partial class LoginStatus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string topAppKey = ConfigurationManager.AppSettings["TopAppKey"];
        string topAppSecret = ConfigurationManager.AppSettings["TopAppSecret"];
        string topParameters = Request.QueryString["top_parameters"];
        string topSign = Request.QueryString["top_sign"];
        string topSession = Request.QueryString["top_session"];
        Session["TopSession"] = topSession;
        try
        {
            if (Utility.VerifyTopResponse(topParameters, topSession, topSign, topAppKey, topAppSecret))
            {
                MemberRepository mRep = new MemberRepository();
                Member member = mRep.Login(topParameters);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(mRep.Ticket));
                Response.Cookies.Add(cookie);
                Response.Redirect("Index.aspx");
            }
            else
            {
                litMsg.Text = "<script>alert('登陆失败，请重新登陆或联系运营商');window.location.href='Login.aspx'</script>";
            }
        }
        catch (Exception ex)
        {
            litMsg.Text = "<script>alert('" + ex.Message + "');window.location.href='Login.aspx'</script>";
        }
    }
}